using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using LowLevelGraphics;
using LowLevelGraphics.Filter;

namespace ImageRecognition2.Forms
{
	/// <summary>
	/// Summary description for Convolution.
	/// </summary>
	public class FormConvolution : FormFilter
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button OK;
		private System.Windows.Forms.Button Cancel;

		private CConvMatrix matrix = new CConvMatrix();
		private System.Windows.Forms.TextBox TL;
		private System.Windows.Forms.TextBox TR;
		private System.Windows.Forms.TextBox TM;
		private System.Windows.Forms.TextBox Pixel;
		private System.Windows.Forms.TextBox MR;
		private System.Windows.Forms.TextBox ML;
		private System.Windows.Forms.TextBox BM;
		private System.Windows.Forms.TextBox BR;
		private System.Windows.Forms.TextBox BL;
		private System.Windows.Forms.TextBox Factor;
		private System.Windows.Forms.TextBox Offset;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FormConvolution()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			OK.DialogResult = System.Windows.Forms.DialogResult.OK;
			Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;

            this.pictureBox1.BackgroundImageLayout = ImageLayout.Zoom;
            
            foreach (Control control in this.Controls)
            {
                TextBox tempControl = control as TextBox;
                if (tempControl != null)
                {
                    tempControl.TextChanged += new EventHandler(tempControl_TextChanged);
                }
            }

            this.Shown += new EventHandler(FormConvolution_Shown);
		}

        void tempControl_TextChanged(object sender, EventArgs e)
        {
            Bitmap bitmap = (Bitmap)m_ImageOriginal.Clone();
            new Convolution3x3(Matrix).Execute(bitmap).Dispose();
            this.pictureBox1.BackgroundImage = bitmap;
            this.pictureBox1.Invalidate();
        }

        void FormConvolution_Shown(object sender, EventArgs e)
        {
            m_ImageOriginal = MainFormSingleton.ActivePictureBox.BackgroundImage;
            this.pictureBox1.BackgroundImage = m_ImageOriginal;
        }

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

        /// <summary>
        /// Convolution Matrix
        /// </summary>
		public CConvMatrix Matrix
		{
			get 
			{
				CConvMatrix mat = new CConvMatrix();
				mat.TopLeft = Convert.ToInt32(TL.Text);
				mat.TopMid = Convert.ToInt32(TM.Text);
				mat.TopRight = Convert.ToInt32(TR.Text);
				mat.MidLeft = Convert.ToInt32(ML.Text);
				mat.MidRight = Convert.ToInt32(MR.Text);
				mat.BottomLeft = Convert.ToInt32(BL.Text);
				mat.BottomMid = Convert.ToInt32(BM.Text);
				mat.BottomRight = Convert.ToInt32(BR.Text);
				mat.Pixel = Convert.ToInt32(Pixel.Text);
				mat.Factor = Convert.ToInt32(Factor.Text);
				mat.Offset = Convert.ToInt32(Offset.Text);
				return mat;
			}
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.TL = new System.Windows.Forms.TextBox();
            this.TR = new System.Windows.Forms.TextBox();
            this.TM = new System.Windows.Forms.TextBox();
            this.Pixel = new System.Windows.Forms.TextBox();
            this.MR = new System.Windows.Forms.TextBox();
            this.ML = new System.Windows.Forms.TextBox();
            this.BM = new System.Windows.Forms.TextBox();
            this.BR = new System.Windows.Forms.TextBox();
            this.BL = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.Factor = new System.Windows.Forms.TextBox();
            this.Offset = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.OK = new System.Windows.Forms.Button();
            this.Cancel = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.trackbZoomSlider)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackbAmount)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // trackbZoomSlider
            // 
            this.trackbZoomSlider.Location = new System.Drawing.Point(116, 377);
            this.trackbZoomSlider.Size = new System.Drawing.Size(100, 63);
            // 
            // chkbPreview
            // 
            this.chkbPreview.Location = new System.Drawing.Point(395, 17);
            // 
            // cbCancel
            // 
            this.cbCancel.Location = new System.Drawing.Point(192, 202);
            this.cbCancel.Size = new System.Drawing.Size(120, 32);
            // 
            // cbOK
            // 
            this.cbOK.Location = new System.Drawing.Point(192, 161);
            this.cbOK.Size = new System.Drawing.Size(120, 32);
            // 
            // lbAmount
            // 
            this.lbAmount.Location = new System.Drawing.Point(38, 424);
            // 
            // tbAmount
            // 
            this.tbAmount.Location = new System.Drawing.Point(255, 424);
            this.tbAmount.Size = new System.Drawing.Size(62, 22);
            // 
            // cb100Percent
            // 
            this.cb100Percent.Location = new System.Drawing.Point(226, 383);
            this.cb100Percent.Size = new System.Drawing.Size(75, 32);
            // 
            // trackbAmount
            // 
            this.trackbAmount.Location = new System.Drawing.Point(20, 450);
            this.trackbAmount.Size = new System.Drawing.Size(339, 41);
            // 
            // pictureBox1
            // 
            this.pictureBox1.Location = new System.Drawing.Point(21, 13);
            this.pictureBox1.Size = new System.Drawing.Size(291, 140);
            // 
            // TL
            // 
            this.TL.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.TL.Location = new System.Drawing.Point(19, 166);
            this.TL.Name = "TL";
            this.TL.Size = new System.Drawing.Size(29, 22);
            this.TL.TabIndex = 0;
            this.TL.Text = "0";
            // 
            // TR
            // 
            this.TR.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.TR.Location = new System.Drawing.Point(115, 166);
            this.TR.Name = "TR";
            this.TR.Size = new System.Drawing.Size(29, 22);
            this.TR.TabIndex = 1;
            this.TR.Text = "0";
            // 
            // TM
            // 
            this.TM.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.TM.Location = new System.Drawing.Point(67, 166);
            this.TM.Name = "TM";
            this.TM.Size = new System.Drawing.Size(29, 22);
            this.TM.TabIndex = 2;
            this.TM.Text = "0";
            // 
            // Pixel
            // 
            this.Pixel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.Pixel.Location = new System.Drawing.Point(67, 203);
            this.Pixel.Name = "Pixel";
            this.Pixel.Size = new System.Drawing.Size(29, 22);
            this.Pixel.TabIndex = 5;
            this.Pixel.Text = "1";
            // 
            // MR
            // 
            this.MR.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.MR.Location = new System.Drawing.Point(115, 203);
            this.MR.Name = "MR";
            this.MR.Size = new System.Drawing.Size(29, 22);
            this.MR.TabIndex = 4;
            this.MR.Text = "0";
            // 
            // ML
            // 
            this.ML.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.ML.Location = new System.Drawing.Point(19, 203);
            this.ML.Name = "ML";
            this.ML.Size = new System.Drawing.Size(29, 22);
            this.ML.TabIndex = 3;
            this.ML.Text = "0";
            // 
            // BM
            // 
            this.BM.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.BM.Location = new System.Drawing.Point(67, 240);
            this.BM.Name = "BM";
            this.BM.Size = new System.Drawing.Size(29, 22);
            this.BM.TabIndex = 8;
            this.BM.Text = "0";
            // 
            // BR
            // 
            this.BR.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.BR.Location = new System.Drawing.Point(115, 240);
            this.BR.Name = "BR";
            this.BR.Size = new System.Drawing.Size(29, 22);
            this.BR.TabIndex = 7;
            this.BR.Text = "0";
            // 
            // BL
            // 
            this.BL.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.BL.Location = new System.Drawing.Point(19, 240);
            this.BL.Name = "BL";
            this.BL.Size = new System.Drawing.Size(29, 22);
            this.BL.TabIndex = 6;
            this.BL.Text = "0";
            // 
            // label1
            // 
            this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label1.Location = new System.Drawing.Point(163, 249);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(9, 26);
            this.label1.TabIndex = 9;
            this.label1.Text = "/";
            // 
            // Factor
            // 
            this.Factor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.Factor.Location = new System.Drawing.Point(192, 240);
            this.Factor.Name = "Factor";
            this.Factor.Size = new System.Drawing.Size(28, 22);
            this.Factor.TabIndex = 10;
            this.Factor.Text = "1";
            // 
            // Offset
            // 
            this.Offset.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.Offset.Location = new System.Drawing.Point(268, 240);
            this.Offset.Name = "Offset";
            this.Offset.Size = new System.Drawing.Size(29, 22);
            this.Offset.TabIndex = 11;
            this.Offset.Text = "0";
            // 
            // label2
            // 
            this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label2.Location = new System.Drawing.Point(240, 249);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(9, 26);
            this.label2.TabIndex = 12;
            this.label2.Text = "+";
            // 
            // OK
            // 
            this.OK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.OK.Location = new System.Drawing.Point(21, 284);
            this.OK.Name = "OK";
            this.OK.Size = new System.Drawing.Size(90, 27);
            this.OK.TabIndex = 13;
            this.OK.Text = "OK";
            // 
            // Cancel
            // 
            this.Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.Cancel.Location = new System.Drawing.Point(222, 284);
            this.Cancel.Name = "Cancel";
            this.Cancel.Size = new System.Drawing.Size(90, 27);
            this.Cancel.TabIndex = 14;
            this.Cancel.Text = "Cancel";
            // 
            // FormConvolution
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
            this.ClientSize = new System.Drawing.Size(395, 332);
            this.Controls.Add(this.Cancel);
            this.Controls.Add(this.OK);
            this.Controls.Add(this.Pixel);
            this.Controls.Add(this.MR);
            this.Controls.Add(this.BL);
            this.Controls.Add(this.BR);
            this.Controls.Add(this.BM);
            this.Controls.Add(this.TL);
            this.Controls.Add(this.TR);
            this.Controls.Add(this.TM);
            this.Controls.Add(this.ML);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.Offset);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.Factor);
            this.Name = "FormConvolution";
            this.Text = "Convolution";
            this.Load += new System.EventHandler(this.FormConvolution_Load);
            this.Controls.SetChildIndex(this.Factor, 0);
            this.Controls.SetChildIndex(this.label1, 0);
            this.Controls.SetChildIndex(this.Offset, 0);
            this.Controls.SetChildIndex(this.label2, 0);
            this.Controls.SetChildIndex(this.ML, 0);
            this.Controls.SetChildIndex(this.TM, 0);
            this.Controls.SetChildIndex(this.TR, 0);
            this.Controls.SetChildIndex(this.TL, 0);
            this.Controls.SetChildIndex(this.cbCancel, 0);
            this.Controls.SetChildIndex(this.pictureBox1, 0);
            this.Controls.SetChildIndex(this.BM, 0);
            this.Controls.SetChildIndex(this.BR, 0);
            this.Controls.SetChildIndex(this.BL, 0);
            this.Controls.SetChildIndex(this.MR, 0);
            this.Controls.SetChildIndex(this.Pixel, 0);
            this.Controls.SetChildIndex(this.cbOK, 0);
            this.Controls.SetChildIndex(this.OK, 0);
            this.Controls.SetChildIndex(this.Cancel, 0);
            this.Controls.SetChildIndex(this.chkbPreview, 0);
            this.Controls.SetChildIndex(this.trackbAmount, 0);
            this.Controls.SetChildIndex(this.lbAmount, 0);
            this.Controls.SetChildIndex(this.tbAmount, 0);
            this.Controls.SetChildIndex(this.trackbZoomSlider, 0);
            this.Controls.SetChildIndex(this.cb100Percent, 0);
            ((System.ComponentModel.ISupportInitialize)(this.trackbZoomSlider)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackbAmount)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

        private void FormConvolution_Load(object sender, EventArgs e)
        {

        }
	}
}
